package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.*;
import com.heima.media.service.IWmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author wsj
 * @since 2022-03-11
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;

    /**
     * 自媒体文章列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "自媒体文章列表",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "查询参数",required = true,dataType = "WmNewsPageDto")
    @PostMapping("/list")
    public ResponseResult listByPage(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.listByPage(dto);
    }

    /**
     * 自媒体文章发布、修改、保存草稿
     * @param dto
     * @return
     */
    @ApiOperation(value = "自媒体文章发布、修改、保存草稿",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "文章参数",required = true,dataType = "WmNewsInfoDto")
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsInfoDto dto) {
        return wmNewsService.submit(dto);
    }

    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable("id")Integer id){
        return ResponseResult.okResult(wmNewsService.getById(id));
    }

    /**
     * 自媒体文章上架下架
     * @param dto
     * @return
     */
    @ApiOperation(value = "自媒体文章上架下架",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "文章参数",required = true,dataType = "WmNewsDto")
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }

    /**
     * 管理平台查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/findPageByName")
    public ResponseResult findPageByName(@RequestBody NewsAuthDto dto) {
        return wmNewsService.findPageByName(dto);
    }

    /**
     * 查看文章详情
     * @param id
     * @return
     */
    @GetMapping("/findNewsVoById/{id}")
    public ResponseResult findNewsVoById(@PathVariable("id") Integer id) {
        return wmNewsService.findNewsVoById(id);
    }

    /**
     * 人工审核驳回文章
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody WmNewsAuthDto dto) {
        return wmNewsService.authFail(dto);
    }

    /**
     * 人工审核通过文章
     * @param dto
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody WmNewsAuthDto dto) {
        return wmNewsService.authPass(dto);
    }
}
